package com.management.service.wes.impl;

import com.management.common.EasyuiTableResponse;
import com.management.common.ResponseCode;
import com.management.common.ServerResponse;
import com.management.dao.report.JobsXsoMapper;
import com.management.pojo.report.JobsXso;
import com.management.pojo.wes.PurTbRcv;
import com.management.pojo.wes.PurTbRcvd;
import com.management.service.wes.IGzhService;
import com.management.service.wes.IPurTbRcvdService;
import com.management.util.DataSourceContextHolder;
import com.management.vo.gzh.GzhVo;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional(value="transactionManager_prd1", readOnly=false)
public class GzhServiceImpl
        implements IGzhService
{
    @Autowired
    JobsXsoMapper jobsXsoMapper;
    @Autowired
    IPurTbRcvdService purTbRcvdService;

    public EasyuiTableResponse gzh(GzhVo gzhVo)
    {
        DataSourceContextHolder.setDbType("prd1");
        List<GzhVo> gzhList = this.jobsXsoMapper.gzh(gzhVo);
        EasyuiTableResponse response = new EasyuiTableResponse();
        response.setCode(ResponseCode.SUCCESS.getCode());
        response.setRows(gzhList);
        return response;
    }

    public ServerResponse updateJobsXso(JobsXso jobsXso)
    {
        DataSourceContextHolder.setDbType("prd1");
        int i = this.jobsXsoMapper.updateJobsXso(jobsXso);
        if (i > 0)
        {
            PurTbRcv purTbRcv = new PurTbRcv();
            purTbRcv.setDocidsrc(jobsXso.getDocNumber());
            this.purTbRcvdService.deletePurTbRcv(purTbRcv);
            PurTbRcvd purTbRcvd = new PurTbRcvd();
            purTbRcvd.setDocidsrc(jobsXso.getDocNumber());
            this.purTbRcvdService.deletePurTbRcvd(purTbRcvd);
            return ServerResponse.createBySuccessMsg("更新成功");
        }
        return ServerResponse.createByErrorMessage("更新失败");
    }

    public ServerResponse updateJobsXso1(JobsXso jobsXso)
    {
        DataSourceContextHolder.setDbType("prd1");
        int i = this.jobsXsoMapper.updateJobsXso1(jobsXso);
        if (i > 0) {
            return ServerResponse.createBySuccessMsg("更新成功");
        }
        return ServerResponse.createByErrorMessage("更新失败");
    }
}
